#include "meshTypeFunctions.hpp"
#include <catch2/catch_test_macros.hpp>
#include <iostream>

using namespace hms;

TEST_CASE("UniCells"){
	Index
		nx {3},
		ny {4},
		ng {1},
		nxg { nx+2*ng },
		nyg { ny+2*ng };

	scalar
		dx {2},
		dy {1},
		x0 {-5},
		y0 {2};

	auto mesh { uniMeshAs<UniMesh>( nx, ny, dx, dy, false, x0, y0 ) };

	REQUIRE( mesh.cells().areas().size() == nxg*nyg );
	REQUIRE( mesh.cells().circumfs().size() == nxg*nyg );
	REQUIRE( mesh.cells().centroids().rows() == 2 );
	REQUIRE( mesh.cells().centroids().cols() == nxg*nyg );
	REQUIRE( mesh.cells().areas().isApproxToConstant(dx*dy) );
	REQUIRE( mesh.cells().circumfs().isApproxToConstant(2*(dx+dy)) );

	const auto centroids { mesh.cells().centroids() };

	for ( int i{0}; i<nxg; ++i ){
		for ( int j{0}; j<nyg; ++j ){
			Index cell { j*nxg+i };
			REQUIRE( centroids.col(cell).isApprox(
				Vector2s{x0 + (i-ng+0.5)*dx, y0 + (j-ng+0.5)*dy}
			) );
			if (
				( i == 0     && (j == 0 || j == nyg-1) ) ||
				( i == nxg-1 && (j == 0 || j == nyg-1) )
			)
				continue;
		}
	}
}